<template>
  <!-- 业绩提成-审核提交组件 -->
  <div>
    <zm-dialog
      :title="myTitles"
      :visible.sync="params.visible"
      class="panelContainer"
      :before-close="onCancel"
      @cancel="onCancel"
      @confirm="submit"
      :ok-text="myConfirm"
      :size="dialogSize"
    >
      <zm-form :model="params.obj" v-if=" type !== '撤销申诉'">
      <el-row :gutter="24">
        <el-col :span="8">
          <zm-form-item label="当月回款总额:">{{ params.obj.returnedMoney }}</zm-form-item>
        </el-col>
        <el-col :span="8">
          <zm-form-item label="应发提成:">{{ params.obj.shouldPrice }}</zm-form-item>
        </el-col>
        <el-col :span="8">
          <zm-form-item label="核发提成:">{{ params.obj.verifyPrice }}</zm-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="8">
          <zm-form-item label="回款单数:">{{ params.obj.returnedNumber }}</zm-form-item>
        </el-col>
        <el-col :span="8">
          <zm-form-item label="业绩月份:">{{ params.obj.month }}</zm-form-item>
        </el-col>
        <el-col :span="8">
          <zm-form-item label="业绩核算状态:">{{ params.obj.statusName }}</zm-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24" v-if="type === '业绩申诉'">
        <el-col :span="24">
          <zm-form-item label="申诉理由:">
            <el-input
              type="textarea"
              placeholder="请填写申诉理由"
              v-model="remark"
              maxlength="300"
              show-word-limit
              resize="none"
            />
          </zm-form-item>
        </el-col>
      </el-row>
       <el-alert
        :title="clues"
        type="warning"
        show-icon
      />
      </zm-form>
      <el-alert
        v-else
        title="撤销申述确认"
        type="info"
        description="是否确认撤销业绩单申述"
        show-icon
        :closable="false"
      />
    </zm-dialog>
  </div>
</template>

<script>
import dialogMixin from '@/mixins/dialogMixin'
import { setCommission } from '@/api/src/salesmanCommission'
import {getPageList} from '@/api/src/returnedMoney'
export default {
  name: 'ConfirmationPop',
  mixins: [dialogMixin],
  props: {
    params: {
      type: Object,
      required: true
    },
    type: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      remark: '', // 备注
      verifyPriceAll: 0, // 核发提成总额
      returnedData: [] // 回款保存核发提成
    }
  },
  computed: {
    clues () {
      return this.type === '业绩申诉' ? '填写并提交申诉内容，财务将根据实际情况进行业绩修正！' : '确认后无法再次修改，请确认操作！（财务将按照确认的业绩提成进行发放）'
    },
    myTitles () {
      return this.type === '业绩申诉' ? '业绩申诉' : this.type === '业绩确认' ? '业绩确认' : '操作确认'
    },
    myConfirm () {
      return this.type === '业绩申诉' ? '业绩申诉' : this.type === '业绩确认' ? '业绩确认' : '确定'
    },
    resultStatus () {
      return this.type === '业绩申诉' ? '3' : this.type === '撤销申诉' ? '4' : this.params.obj.status
    },
    dialogSize () {
      return this.type === '撤销申诉' ? 'mini' : 'large'
    }
  },
  methods: {
    onCancel () {
      this.$emit('onCancel', false)
    },
    submit () {
      if (this.type === '撤销申诉') {
        this.myDate()
      } else {
        this.$confirm('此操作将进行' + this.type + ', 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.myDate()
        }).catch(() => {})
      }
    },
    async myDate () {
      let _res = await getPageList({month: this.params.month})
      _res.list.forEach(item => {
        this.returnedData.push({returnedNo: item.returnedNo, verifyPrice: item.verifyPrice})
      })
      await setCommission({id: this.params.obj.id, status: this.resultStatus, verifyPriceAll: this.params.obj.verifyPrice, remark: this.remark, returnedData: this.returnedData})
      this.$emit('closeDetailDialog')
      this.onCancel()
      this.$message({
        type: 'success',
        message: '提交成功!'
      })
    }
  }
}
</script>

<style></style>
